﻿using System;
using System.Collections.Specialized;

namespace K3R.Extensions {
	public static class NameValueCollectionExtensions {
		public static string Format(this NameValueCollection collection, string format, params string[] args) {
			var arr = new object[args.Length];
			for (var i = 0; i < arr.Length; i++) {
				arr[i] = collection[args[i]];
			}

			return String.Format(format, arr);
		}

		public static string Format(this NameValueCollection collection, string format, string[] values, params object[] args) {
			var arr = new object[values.Length + args.Length];
			for (var i = 0; i < arr.Length; i++) {
				if (i < values.Length)
					arr[i] = collection[values[i]];
				else arr[i] = args[i - values.Length];
			}

			return String.Format(format, arr);
		}
	}
}
